﻿<phone:PhoneApplicationPage 
    x:Class="UI.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:local="clr-namespace:UI"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    Loaded="PhoneApplicationPage_Loaded"
    shell:SystemTray.IsVisible="False" BackKeyPress="PhoneApplicationPage_BackKeyPress">

    <phone:PhoneApplicationPage.Resources>
        <local:UserImageConverter x:Key="UserImageConverter" />
        <local:GenderImageConverter x:Key="GenderImageConverter" />
        <local:FollowMeStringConverter x:Key="FollowMeStringConverter" />
        <local:FollowedStringConverter x:Key="FollowedStringConverter" />
    </phone:PhoneApplicationPage.Resources>

    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid Name="LayoutRoot" Background="Transparent">
        <controls:Pivot Name="mainPivot" Foreground="#FF0097D5" LoadedPivotItem="mainPivot_LoadedPivotItem" UnloadingPivotItem="mainPivot_UnloadingPivotItem">
            <controls:Pivot.Title>
                <StackPanel Orientation="Horizontal">
                    <Image Source="/UI;component/Images/Logo.png" Height="50" Width="50" />
                    <TextBlock Margin="5,0,0,0" VerticalAlignment="Bottom" FontSize="28" Text="新浪微博" />
                </StackPanel>
            </controls:Pivot.Title>
            <controls:Pivot.Background>
                <ImageBrush ImageSource="/UI;component/Images/PanoramaBackground.png" Stretch="None" AlignmentX="Left" AlignmentY="Top" />
            </controls:Pivot.Background>

            <controls:PivotItem Name="tweetPivotItem">
                <controls:PivotItem.Header>
                    <TextBlock FontSize="50" Margin="0,15,0,-10" Text="微博" />
                </controls:PivotItem.Header>
                <ListBox Name="tweetsListBox" Margin="0,0,-12,0" toolkit:TiltEffect.IsTiltEnabled="True">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="12,0,0,35" Loaded="Tweet_Loaded">
                                <Image VerticalAlignment="Top" HorizontalAlignment="Left" Source="{Binding Path=UserProfileImageUrl, Converter={StaticResource UserImageConverter}}" Height="50" Width="50" />
                                <StackPanel Width="365" Margin="15,-7,0,0">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Foreground="#FF333333" Text="{Binding Path=ScreenName}" TextWrapping="Wrap" FontSize="30" />
                                        <TextBlock Grid.Column="1" Foreground="#FF999999" Text="{Binding Path=CreatedTimeForShow}" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
                                    </Grid>
                                    <TextBlock Foreground="#FF444444" TextWrapping="Wrap" Loaded="TweetText_Loaded" />
                                </StackPanel>
                                <StackPanel.Background>
                                    <SolidColorBrush />
                                </StackPanel.Background>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>

            <controls:PivotItem Name="writeTweetPivotItem">
                <controls:PivotItem.Header>
                    <TextBlock FontSize="50" Margin="0,15,0,-10" Text="发布" />
                </controls:PivotItem.Header>

                <Grid>
                    <StackPanel>
                        <local:WatermarkTextBox WatermarkTextForeground="#FF999999" WatermarkText="有什么新鲜事？" HorizontalAlignment="Left" x:Name="tweetTextBox" VerticalAlignment="Top" Width="455" TextWrapping="Wrap" TextChanged="tweetTextBox_TextChanged" WatermarkHidden="tweetTextBox_WatermarkHidden" WatermarkShown="tweetTextBox_WatermarkShown" />
                        <Grid>
                            <TextBlock Foreground="#FF002060" TextWrapping="Wrap" Name="retweetTextBlock" Margin="12,0" Visibility="Collapsed" />
                            <local:TiltContainer x:Name="tweetImageContainer" toolkit:TiltEffect.IsTiltEnabled="True" Visibility="Collapsed">
                                <Image Width="431" Margin="12,0,0,0" Name="tweetImage" VerticalAlignment="Top" HorizontalAlignment="Left" />
                            </local:TiltContainer>
                        </Grid>
                    </StackPanel>
                    <TextBlock Name="validCharCountTextBlock" Margin="0,-10,12,0" Height="20" Width="300" HorizontalAlignment="Right" FontSize="15" TextAlignment="Right" VerticalAlignment="Top" />
                    <TextBlock Name="invalidCharCountTextBlock" Margin="0,-10,12,0" Height="20" Width="300" HorizontalAlignment="Right" FontSize="15" TextAlignment="Right" VerticalAlignment="Top" Opacity="0" />
                </Grid>
                
            </controls:PivotItem>

            <controls:PivotItem Name="followingPivotItem">
                <controls:PivotItem.Header>
                    <TextBlock FontSize="50" Margin="0,15,0,-10" Text="关注" />
                </controls:PivotItem.Header>
                
                <Grid>
                    <Grid Name="followingGrid">
                        <local:TiltContainer x:Name="followingHintContainer" Width="170" Height="190" Margin="0,-120,0,0" toolkit:TiltEffect.IsTiltEnabled="True" Tap="followingHintContainer_Tap">
                            <StackPanel>
                                <Image Source="/UI;component/Images/following.png" Height="150" Width="150" />
                                <TextBlock Foreground="#FF444444" FontSize="28" Text="获取关注列表" />
                            </StackPanel>
                        </local:TiltContainer>

                        <ListBox Name="followingListBox" Margin="0,0,-12,0" Visibility="Collapsed" toolkit:TiltEffect.IsTiltEnabled="True">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel />
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>

                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Margin="12,0,0,35" Loaded="Following_Loaded">
                                        <Image VerticalAlignment="Top" HorizontalAlignment="Left" Source="{Binding Path=ProfileImageUrl, Converter={StaticResource UserImageConverter}}" Height="50" Width="50" />
                                        <StackPanel Width="365" Margin="15,-7,0,0">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*" />
                                                    <ColumnDefinition Width="Auto" />
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Grid.Column="0" Foreground="#FF333333" Text="{Binding Path=ScreenName}" TextWrapping="Wrap" FontSize="30" />
                                                <TextBlock Grid.Column="1" Foreground="#FF444444" Text="{Binding Path=FollowMe, Converter={StaticResource FollowMeStringConverter}}" HorizontalAlignment="Right" VerticalAlignment="Top" />
                                            </Grid>
                                            <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
                                                <Image Source="{Binding Path=Gender, Converter={StaticResource GenderImageConverter}}" Height="26" Width="22" />
                                                <TextBlock Margin="20,0,0,0" Foreground="#FF444444" Text="{Binding Path=Location}" TextWrapping="Wrap" />
                                            </StackPanel>
                                            <TextBlock Foreground="#FF444444" Text="{Binding Path=Description}" TextWrapping="Wrap" /> 
                                        </StackPanel>
                                        <StackPanel.Background>
                                            <SolidColorBrush />
                                        </StackPanel.Background>
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                    
                    <Grid Name="followGrid" Visibility="Collapsed">
                        <StackPanel>
                            <local:WatermarkTextBox WatermarkTextForeground="#FF999999" WatermarkText="想关注谁？" HorizontalAlignment="Left" x:Name="userNameTextBox" VerticalAlignment="Top" Width="455" TextChanged="userNameTextBox_TextChanged" />
                            <Grid>
                                <StackPanel Name="userInfoPanel" Orientation="Horizontal" Margin="12,0,0,35" Visibility="Collapsed">
                                    <Image VerticalAlignment="Top" HorizontalAlignment="Left" Source="{Binding Path=ProfileImageUrl, Converter={StaticResource UserImageConverter}}" Height="50" Width="50" />
                                    <StackPanel Width="365" Margin="15,-7,0,0">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0" Foreground="#FF333333" Text="{Binding Path=ScreenName}" TextWrapping="Wrap" FontSize="30" />
                                            <TextBlock Grid.Column="1" Foreground="#FFC0504D" Text="{Binding Converter={StaticResource FollowedStringConverter}}" HorizontalAlignment="Right" VerticalAlignment="Top" />
                                        </Grid>
                                        <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
                                            <Image Source="{Binding Path=Gender, Converter={StaticResource GenderImageConverter}}" Height="26" Width="22" />
                                            <TextBlock Margin="20,0,0,0" Foreground="#FF444444" Text="{Binding Path=Location}" TextWrapping="Wrap" />
                                        </StackPanel>
                                        <TextBlock Foreground="#FF444444" Text="{Binding Path=Description}" TextWrapping="Wrap" />
                                    </StackPanel>
                                </StackPanel>
                                <TextBlock Name="noUserTextBlock" TextAlignment="Center" Foreground="#FFC0504D" Text="该用户不存在！" FontSize="30" Margin="12,30,12,0" Visibility="Collapsed" />
                            </Grid>
                        </StackPanel>
                    </Grid>
                </Grid>
            </controls:PivotItem>

        </controls:Pivot>

        <local:LoadingIndicator x:Name="loadingIndicator" VerticalAlignment="Bottom" />
    </Grid>

    <!--Sample code showing usage of ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>